import 'package:example/pages/home/index.dart';
import 'package:example/pages/plugins/plugins_view.dart';
import 'package:example/pages/widgets/widgets_view.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:getx_scaffold_ohos/getx_scaffold_ohos.dart';

import '../todo/todo_view.dart';
import 'main_controller.dart';

class MainPage extends StatelessWidget {
  MainPage({super.key});

  final MainController controller = Get.put(MainController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MainController>(
        id: 'main',
        init: controller,
        builder: (controller) {
          return AnnotatedRegion<SystemUiOverlayStyle>(
            value: SystemUiOverlayStyle.dark,
            child: Scaffold(
              backgroundColor: Colors.white,
              body: PageView(
                controller: controller.pageController,
                onPageChanged: (index) {
                  controller.changePage(index);
                },
                children: [
                  TodoPage(),
                  const HomePage(),
                  WidgetsPage(),
                  PluginsPage()
                ],
              ),
              bottomNavigationBar: NavigationX(
                currentIndex: controller.pageIndex,
                items: [
                  NavigationItemModel(
                    label: '待办',
                    icon: Icons.toc_rounded,
                    selectedIcon: Icons.toc_rounded,
                  ),
                  NavigationItemModel(
                    label: '案例',
                    icon: Icons.cases_rounded,
                    selectedIcon: Icons.cases_rounded,
                  ),
                  NavigationItemModel(
                    label: '组件',
                    icon: Icons.widgets,
                    selectedIcon: Icons.widgets,
                  ),
                  NavigationItemModel(
                    label: '插件',
                    icon: Icons.extension,
                    selectedIcon: Icons.extension,
                  ),
                ],
                onTap: (index) {
                  controller.changePage(index);
                },
              ),
            ),
          );
        });
  }
}
